package cn.szzsi.service;

import cn.szzsi.common.bean.HtmlConfig;
import cn.szzsi.common.bean.SystemConfig;
import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.kit.SystemConfigUtil;
import cn.szzsi.common.kit.TemplateConfigUtil;
import cn.szzsi.common.model.*;
import cn.szzsi.common.model.zshop.PlateformConfig;
import com.jfinal.core.JFinal;
import org.apache.commons.lang3.StringUtils;
import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.resource.WebAppResourceLoader;

import javax.servlet.ServletContext;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Service实现类 - 生成静态
 * 
 */
public class HtmlService {
	
	public static final HtmlService service = new HtmlService();
	
	public void buildHtml(String templateFilePath, String htmlFilePath, Map<String, Object> data) {
		try {
			ServletContext servletContext = JFinal.me().getServletContext();
			WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
			Configuration cfg = Configuration.defaultConfiguration();
			GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
			org.beetl.core.Template template = gt.getTemplate(templateFilePath);
			template.binding(data);

			File htmlFile = new File(servletContext.getRealPath(htmlFilePath));
			File htmlDirectory = htmlFile.getParentFile();
			if (!htmlDirectory.exists()) {
				htmlDirectory.mkdirs();
			}
			Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8"));
			template.renderTo(out);
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	// 获取公共数据
	public Map<String, Object> getCommonData() {
		Map<String, Object> commonData = new HashMap<String, Object>();
		ServletContext servletContext = JFinal.me().getServletContext();
		SystemConfig systemConfig = SystemConfigUtil.getSystemConfig();
		commonData.put("customerType","");
		commonData.put("base", servletContext.getContextPath());
		commonData.put("systemConfig", systemConfig);		
		commonData.put("topNavigationList", Navigation.dao.getTopNavigationList());
		commonData.put("middleNavigationList", Navigation.dao.getMiddleNavigationList());
		commonData.put("bottomNavigationList", Navigation.dao.getBottomNavigationList());
		commonData.put("friendLinkList", Friendlink.dao.getAll());
		commonData.put("pictureFriendLinkList", Friendlink.dao.getPictureFriendLinkList());
		commonData.put("textFriendLinkList", Friendlink.dao.getTextFriendLinkList());
		commonData.put("footer", Footer.dao.getFooter());
		return commonData;
	}

	// 获取商户公共数据
	public Map<String, Object> getBusinessCommonData(String uid) {
		Map<String, Object> commonData = new HashMap<String, Object>();
		ServletContext servletContext = JFinal.me().getServletContext();
		SystemConfig systemConfig = SystemConfigUtil.getSystemConfig();
		SiteConfig siteConfig = SiteConfig.getByShopId(uid);
		commonData.put("customerType","b_customer");
		commonData.put("base", servletContext.getContextPath());
		commonData.put("siteConfig", siteConfig);
		commonData.put("systemConfig", systemConfig);
		commonData.put("businessTopNavigationList", Navigation.dao.getBusinessTopNavigationList(uid));
		commonData.put("businessMiddleNavigationList", Navigation.dao.getBusinessMiddleNavigationList(uid));
		commonData.put("businessBottomNavigationList", Navigation.dao.getBusinessBottomNavigationList(uid));
		commonData.put("businessAdImgList", Admanage.dao.getAdImageByUid(uid));
		commonData.put("friendLinkList", Friendlink.dao.getBusinessAll(uid));
		commonData.put("businessPictureFriendLinkList", Friendlink.dao.getBusinessPictureFriendLinkList(uid));
		commonData.put("businessTextFriendLinkList", Friendlink.dao.getBusinessTextFriendLinkList(uid));
		commonData.put("footer", Footer.dao.getFooter());
		commonData.put("businessHotSearchList", SiteConfig.dao.getHotSearchByUid(uid));//热搜关键词集合

		//平台
		PlateformConfig plateformConfig=PlateformConfig.dao.findById(1);
		commonData.put("plateformConfig",plateformConfig);
		//平台
		return commonData;
	}
	
	public void baseJavascriptBuildHtml() {
		Map<String, Object> data = getCommonData();
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.BASE_JAVASCRIPT);
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	/**
	 * 平台的生成首页
	 */
	public void indexBuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.INDEX);
		Map<String, Object> data = getCommonData();
		data.put("rootProductCategoryList", ProductCategory.dao.getPlatformRootProductCategoryList());
		data.put("bestProductList", Product.dao.getPlatformBestProductList(Product.MAX_BEST_PRODUCT_LIST_COUNT));
		data.put("hotProductList", Product.dao.getPlatformHotProductList(Product.MAX_HOT_PRODUCT_LIST_COUNT));
		data.put("newProductList", Product.dao.getPlatformNewProductList(Product.MAX_NEW_PRODUCT_LIST_COUNT));
		List<ProductCategory> allProductCategory = ProductCategory.dao.getAll();
		data.put("allProductCategoryList", allProductCategory);
		Map<String, List<ProductCategory>> productCategoryMap = new HashMap<String, List<ProductCategory>>();
		Map<String, List<Product>> bestProductMap = new HashMap<String, List<Product>>();
		Map<String, List<Product>> hotProductMap = new HashMap<String, List<Product>>();
		Map<String, List<Product>> newProductMap = new HashMap<String, List<Product>>();
		for (ProductCategory productCategory : allProductCategory) {
			String productCategory_id = productCategory.getStr("id");
			productCategoryMap.put(productCategory_id, productCategory.getPlatformChildrenProductCategoryList(productCategory));
			bestProductMap.put(productCategory_id, Product.dao.getPlatformBestProductList(productCategory_id, Product.MAX_BEST_PRODUCT_LIST_COUNT));
			hotProductMap.put(productCategory_id, Product.dao.getPlatformHotProductList(productCategory_id, Product.MAX_HOT_PRODUCT_LIST_COUNT));
			newProductMap.put(productCategory_id, Product.dao.getPlatformNewProductList(productCategory_id, Product.MAX_NEW_PRODUCT_LIST_COUNT));
		}
		data.put("productCategoryMap", productCategoryMap);
		data.put("bestProductMap", bestProductMap);
		data.put("hotProductMap", hotProductMap);
		data.put("newProductMap", newProductMap);

		data.put("rootArticleCategoryList", ArticleCategory.dao.getPlatformRootArticleCategoryList());
		data.put("recommendArticleList", Article.dao.getPlatformRecommendArticleList(Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
		data.put("hotArticleList", Article.dao.getPlatformHotArticleList(Article.MAX_HOT_ARTICLE_LIST_COUNT));
		data.put("newArticleList", Article.dao.getPlateformNewArticleList(Article.MAX_NEW_ARTICLE_LIST_COUNT));
		List<ArticleCategory> allArticleCategory = ArticleCategory.dao.getAll();
		data.put("allArticleCategoryList", allArticleCategory);
		Map<String, List<ArticleCategory>> articleCategoryMap = new HashMap<String, List<ArticleCategory>>();
		Map<String, List<Article>> recommendArticleMap = new HashMap<String, List<Article>>();
		Map<String, List<Article>> hotArticleMap = new HashMap<String, List<Article>>();
		Map<String, List<Article>> newArticleMap = new HashMap<String, List<Article>>();
		for (ArticleCategory articleCategory : allArticleCategory) {
			articleCategoryMap.put(articleCategory.getStr("id"), articleCategory.getPlatformChildrenArticleCategoryList(articleCategory));
			recommendArticleMap.put(articleCategory.getStr("id"), Article.dao.getPlatformRecommendArticleList(articleCategory, Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
			hotArticleMap.put(articleCategory.getStr("id"), Article.dao.getPlatformHotArticleList(articleCategory, Article.MAX_HOT_ARTICLE_LIST_COUNT));
			newArticleMap.put(articleCategory.getStr("id"), Article.dao.getPlatformNewArticleList(articleCategory, Article.MAX_NEW_ARTICLE_LIST_COUNT));
		}
		data.put("articleCategoryMap", articleCategoryMap);
		data.put("recommendArticleMap", recommendArticleMap);
		data.put("hotArticleMap", hotArticleMap);
		data.put("newArticleMap", newArticleMap);

		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	public static void main(String[] args) {
		System.out.println(StringUtils.equalsIgnoreCase("-1","1"));
	}

	/**
	 * 商户的生成首页
	 * @param siteConfig
	 */
	public void indexBuildHtml(SiteConfig siteConfig) {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.INDEX);
		String uid=siteConfig.getUid();//店铺id
		String shopAlias=siteConfig.getShopAlias();//店铺别名
		Map<String, Object> data = getBusinessCommonData(uid);
		data.put("shopId",uid);
		data.put("shopAlias",shopAlias);
		//平台分配
		//data.put("rootProductCategoryList", ProductCategory.dao.getBusinessRootProductCategoryList(uid));
		data.put("rootProductCategoryList", ProductCategory.dao.getBusinessRootProductCategoryListByPlateformDivide(uid));
		//平台分配
		data.put("bestProductList", Product.dao.getBusinessBestProductList(uid,Product.MAX_BEST_PRODUCT_LIST_COUNT));//精品
		data.put("hotProductList", Product.dao.getBusinessHotProductList(uid,Product.MAX_HOT_PRODUCT_LIST_COUNT));//热销
		data.put("newProductList", Product.dao.getBusinessNewProductList(uid,Product.MAX_NEW_PRODUCT_LIST_COUNT));//新品
		List<ProductCategory> allProductCategory = ProductCategory.dao.getByUidByPlateformDivide(uid);
		data.put("allProductCategoryList", allProductCategory);
		Map<String, List<ProductCategory>> productCategoryMap = new HashMap<String, List<ProductCategory>>();
		Map<String, List<Product>> bestProductMap = new HashMap<String, List<Product>>();
		Map<String, List<Product>> hotProductMap = new HashMap<String, List<Product>>();
		Map<String, List<Product>> newProductMap = new HashMap<String, List<Product>>();
		for (ProductCategory productCategory : allProductCategory) {
			String productCategory_id = productCategory.getStr("id");
			productCategoryMap.put(productCategory_id, productCategory.getBusinessChildrenProductCategoryList(uid,productCategory));
			bestProductMap.put(productCategory_id, Product.dao.getBusinessBestProductList(uid,productCategory_id, Product.MAX_BEST_PRODUCT_LIST_COUNT));
			hotProductMap.put(productCategory_id, Product.dao.getBusinessHotProductList(uid,productCategory_id, Product.MAX_HOT_PRODUCT_LIST_COUNT));
			newProductMap.put(productCategory_id, Product.dao.getBusinessNewProductList(uid,productCategory_id, Product.MAX_NEW_PRODUCT_LIST_COUNT));
		}
		data.put("productCategoryMap", productCategoryMap);
		data.put("bestProductMap", bestProductMap);
		data.put("hotProductMap", hotProductMap);
		data.put("newProductMap", newProductMap);
		data.put("cheapProductList", Product.dao.getBusinessCheapProductList(uid,null,8));

		data.put("rootArticleCategoryList", ArticleCategory.dao.getBusinessRootArticleCategoryList(uid));
		data.put("recommendArticleList", Article.dao.getBusinessRecommendArticleList(uid, Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
		data.put("hotArticleList", Article.dao.getBusinessHotArticleList(uid, Article.MAX_HOT_ARTICLE_LIST_COUNT));
		data.put("newArticleList", Article.dao.getBusinessNewArticleList(uid, Article.MAX_NEW_ARTICLE_LIST_COUNT));
		data.put("indexArticleList", Article.dao.getBusinessIndexArticleList(uid, Article.MAX_NEW_ARTICLE_LIST_COUNT));
		data.put("allArticleList", Article.dao.getBusinessArticleList(uid));
		List<ArticleCategory> allArticleCategory = ArticleCategory.dao.getByUid(uid);
		data.put("allArticleCategoryList", allArticleCategory);
		Map<String, List<ArticleCategory>> articleCategoryMap = new HashMap<String, List<ArticleCategory>>();
		Map<String, List<Article>> recommendArticleMap = new HashMap<String, List<Article>>();
		Map<String, List<Article>> hotArticleMap = new HashMap<String, List<Article>>();
		Map<String, List<Article>> newArticleMap = new HashMap<String, List<Article>>();
		for (ArticleCategory articleCategory : allArticleCategory) {
			articleCategoryMap.put(articleCategory.getStr("id"), articleCategory.getBusinessChildrenArticleCategoryList(uid,articleCategory));
			recommendArticleMap.put(articleCategory.getStr("id"), Article.dao.getBusinessRecommendArticleList(uid,articleCategory, Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
			hotArticleMap.put(articleCategory.getStr("id"), Article.dao.getBusinessHotArticleList(uid,articleCategory, Article.MAX_HOT_ARTICLE_LIST_COUNT));
			newArticleMap.put(articleCategory.getStr("id"), Article.dao.getBusinessNewArticleList(uid,articleCategory, Article.MAX_NEW_ARTICLE_LIST_COUNT));
		}
		data.put("articleCategoryMap", articleCategoryMap);
		data.put("recommendArticleMap", recommendArticleMap);
		data.put("hotArticleMap", hotArticleMap);
		data.put("newArticleMap", newArticleMap);

		String htmlFilePath = htmlConfig.getHtmlFilePath();
		/*String templateFilePath = htmlConfig.getTemplateFilePath();
		//根据商户的信息来个性化生成
		Template pcTemplate= Template.getByUseridAndAgent(uid,"pc");
		Template wapTemplate= Template.getByUseridAndAgent(uid,"wap");
		if(pcTemplate!=null){//pc模板
			String pcPath=pcTemplate.getStr("path");
			data.put("path",pcPath);
			htmlFilePath = "/shop/"+shopAlias+htmlFilePath;
			templateFilePath = StringUtils.replace(templateFilePath,"/shop/index.html", CommonUtil.getRealTemplatePath(pcPath,"index.html"));
			data.put(CommonUtil.BUSINESS_TEMPLATE_PATH,pcPath);
			buildHtml(templateFilePath, htmlFilePath, data);
		}
		if(wapTemplate!=null){//wap模板
			String wapPath=wapTemplate.get("path");
			data.put("path",wapPath);
			htmlFilePath = "/shop/"+shopAlias+"/wap.html";
			String wapTemplateFilePath= CommonUtil.getRealTemplatePath(wapPath,"index.html");
			data.put(CommonUtil.BUSINESS_TEMPLATE_PATH,wapPath);
			buildHtml(wapTemplateFilePath, htmlFilePath, data);

		}*/
		htmlFilePath = "/shop/"+shopAlias+"/index.html";
		buildHtml("/template/pc1/html/index.html", htmlFilePath, data);

		htmlFilePath = "/shop/"+shopAlias+"/wap.html";
		buildHtml("/template/default/html/index.html", htmlFilePath, data);

	}

	
	public void articleContentBuildHtml(Article article) {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.ARTICLE_CONTENT);
		ArticleCategory articleCategory = article.getArticleCategory();
		Map<String, Object> data = getCommonData();
		data.put("article", article);
		data.put("pathList", ArticleCategory.dao.getArticleCategoryPathList(article));
		data.put("rootArticleCategoryList", ArticleCategory.dao.getPlatformRootArticleCategoryList());
		data.put("recommendArticleList", Article.dao.getPlatformRecommendArticleList(articleCategory, Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
		data.put("hotArticleList", Article.dao.getPlatformHotArticleList(articleCategory, Article.MAX_HOT_ARTICLE_LIST_COUNT));
		data.put("newArticleList", Article.dao.getNewArticleList(articleCategory, Article.MAX_NEW_ARTICLE_LIST_COUNT));
		String htmlFilePath = article.getStr("htmlFilePath");
		String prefix = StringUtils.substringBeforeLast(htmlFilePath, ".");
		String extension = StringUtils.substringAfterLast(htmlFilePath, ".");
		List<String> pageContentList = article.getPageContentList();
		article.set("pageCount",pageContentList.size());
		article.update();
		//articleDao.flush();
		for (int i = 0; i < pageContentList.size(); i++) {
			data.put("content", pageContentList.get(i));
			data.put("pageNumber", i + 1);
			data.put("pageCount", pageContentList.size());
			String templateFilePath = htmlConfig.getTemplateFilePath();
			String currentHtmlFilePath = null;
			if (i == 0) {
				currentHtmlFilePath = htmlFilePath;
			} else {
				currentHtmlFilePath = prefix + "_" + (i + 1) + "." + extension;
			}
			buildHtml(templateFilePath, currentHtmlFilePath, data);
		}
	}

	/**
	 * 商户生成静态文章
	 * @param article
	 * @param isMobile 是否生成wap
	 * @param path 模板路径
     * @param
     */
	public void businessArticleContentBuildHtml(Article article, boolean isMobile, String path, String uid, String shopAlias) {
		HtmlConfig htmlConfig = TemplateConfigUtil.getBusinessHtmlConfig(HtmlConfig.ARTICLE_CONTENT);
		ArticleCategory articleCategory = article.getArticleCategory();//文章分类
		Map<String, Object> data = getBusinessCommonData(uid);
		data.put(CommonUtil.BUSINESS_TEMPLATE_PATH,path);
		data.put("shopId",uid);
		data.put("shopAlias",shopAlias);
		data.put("article", article);
		data.put("pathList", ArticleCategory.dao.getArticleCategoryPathList(article));
		data.put("rootArticleCategoryList", ArticleCategory.dao.getBusinessRootArticleCategoryList(uid));
		data.put("recommendArticleList", Article.dao.getBusinessRecommendArticleList(uid,articleCategory, Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
		data.put("hotArticleList", Article.dao.getBusinessHotArticleList(uid,articleCategory, Article.MAX_HOT_ARTICLE_LIST_COUNT));
		data.put("newArticleList", Article.dao.getBusinessNewArticleList(uid,articleCategory, Article.MAX_NEW_ARTICLE_LIST_COUNT));
		String htmlFilePath = article.getStr("htmlFilePath");
		String prefix = StringUtils.substringBeforeLast(htmlFilePath, ".");
		String extension = StringUtils.substringAfterLast(htmlFilePath, ".");
		List<String> pageContentList = article.getPageContentList();
		article.set("pageCount",pageContentList.size());
		article.update();
		data.put("allArticleList", Article.dao.getBusinessArticleList(uid));
		//articleDao.flush();
		for (int i = 0; i < pageContentList.size(); i++) {
			data.put("content", pageContentList.get(i));
			data.put("pageNumber", i + 1);
			data.put("pageCount", pageContentList.size());
			String templateFilePath = htmlConfig.getTemplateFilePath();
			templateFilePath = StringUtils.replace(templateFilePath,"/shop/","/template/"+path+"/html/");
			String currentHtmlFilePath = null;
			if (i == 0) {
				currentHtmlFilePath = htmlFilePath;
			} else {
				currentHtmlFilePath = prefix + "_" + (i + 1) + "." + extension;
			}
			buildHtml(templateFilePath, currentHtmlFilePath, data);
		}
	}
	
	public void productContentBuildHtml(Product product) {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.PRODUCT_CONTENT);
		String productCategory_id = product.getStr("productCategory_id");
		Map<String, Object> data = getCommonData();
		data.put("product", product);
		data.put("pathList", ProductCategory.dao.getProductCategoryPathList(product));
		data.put("rootProductCategoryList", ProductCategory.dao.getPlatformRootProductCategoryList());
		data.put("bestProductList", Product.dao.getPlatformBestProductList(productCategory_id, Product.MAX_BEST_PRODUCT_LIST_COUNT));
		data.put("hotProductList", Product.dao.getPlatformHotProductList(productCategory_id, Product.MAX_HOT_PRODUCT_LIST_COUNT));
		data.put("newProductList", Product.dao.getPlatformNewProductList(productCategory_id, Product.MAX_NEW_PRODUCT_LIST_COUNT));
		String htmlFilePath = product.getStr("htmlFilePath");;
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	/**
	 * 商户生成静态产品
	 * @param product
	 * @param path
     * @param shopAlias
     */
	public void businessProductContentBuildHtml(Product product, String path, String shopAlias, String uid) {
		HtmlConfig htmlConfig = TemplateConfigUtil.getBusinessHtmlConfig(HtmlConfig.PRODUCT_CONTENT);
		String productCategory_id = product.getStr("productCategory_id");
		Map<String, Object> data = getBusinessCommonData(uid);
		data.put(CommonUtil.BUSINESS_TEMPLATE_PATH,path);
		data.put("shopId",uid);
		data.put("shopAlias",shopAlias);
		data.put("product", product);
		data.put("pathList", ProductCategory.dao.getProductCategoryPathList(product));
		data.put("rootProductCategoryList", ProductCategory.dao.getBusinessRootProductCategoryList(uid));
		data.put("bestProductList", Product.dao.getBusinessBestProductList(uid,productCategory_id, Product.MAX_BEST_PRODUCT_LIST_COUNT));
		data.put("hotProductList", Product.dao.getBusinessHotProductList(uid,productCategory_id, Product.MAX_HOT_PRODUCT_LIST_COUNT));
		data.put("newProductList", Product.dao.getBusinessNewProductList(uid,productCategory_id, Product.MAX_NEW_PRODUCT_LIST_COUNT));
		//data.put("allArticleList", Article.dao.getBusinessArticleList(uid));

		//规格特征
		data.put("specification", Specification.me.getAllSpecificationByProduct(product));
		//查询商品评论(文字)
		data.put("evaluateList", ProductEvaluate.dao.getEvaluateList(product.getStr("id")));

		String htmlFilePath = product.getStr("htmlFilePath");//文件路径
		String templateFilePath = htmlConfig.getTemplateFilePath();//模板路径
		templateFilePath = StringUtils.replace(templateFilePath,"/shop/","/template/"+path+"/html/");
		buildHtml(templateFilePath, htmlFilePath, data);
	}
	
	public void errorPageBuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.ERROR_PAGE);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "系统出现异常，请与管理员联系！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}
	
	public void errorPageAccessDeniedBuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.ERROR_PAGE);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "您无此访问权限！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}
	
	public void errorPage500BuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.ERROR_PAGE_500);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "系统出现异常，请与管理员联系！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}
	
	public void errorPage404BuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.ERROR_PAGE_404);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "您访问的页面不存在！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}
	
	public void errorPage403BuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil.getHtmlConfig(HtmlConfig.ERROR_PAGE_403);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "系统出现异常，请与管理员联系！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

}
